package org.firefly.db.util;

import java.sql.Connection;
import java.sql.SQLException;

import org.firefly.db.dialect.DerbyDialect;
import org.firefly.db.dialect.IDialect;
import org.firefly.db.dialect.MSSQL2005Dialect;
import org.firefly.db.dialect.MySQLDialect;
import org.firefly.db.dialect.OracleDialect;
import org.firefly.db.meta.DBMetaImpl;
import org.firefly.db.meta.IDBMeta;

/**
 * 数据库信息
 * @author firefly
 * @version 2.0
 */
public class DBInfo {
	private IDialect dialect;
	private IDBMeta meta;
	private Connection conn;
	private String schema;
	private DBName dbName;
	private String url;
	public DBInfo(Connection conn, String schema, DBName dbName) throws SQLException {
		super();
		this.conn = conn;
		this.schema = schema;
		this.dbName = dbName;
		this.meta = new DBMetaImpl(conn, schema);
		switch (dbName) {
			case Oracle:
				dialect = new OracleDialect();
				break;
			case Mysql:
				dialect = new MySQLDialect();
				break;
			case SqlServer2005:
				dialect = new MSSQL2005Dialect();
				break;
			case Derby:
				dialect = new DerbyDialect();
				break;
		}
	}
	public IDialect getDialect() {
		return dialect;
	}
	public IDBMeta getMeta() {
		return meta;
	}
	public Connection getConn() {
		return conn;
	}
	public String getSchema() {
		return schema;
	}
	public DBName getDbName() {
		return dbName;
	}
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
}
